/**
 * 
 */
package cz.cvut.fit.crhonjar.mi.run.hawera.tree.block;

import java.util.LinkedList;
import java.util.List;

import cz.cvut.fit.crhonjar.mi.run.hawera.symboltable.HashSymbolTable;
import cz.cvut.fit.crhonjar.mi.run.hawera.symboltable.SymbolTable;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.statement.StatementTree;

/**
 * represents block
 * 
 * @author Jarec
 * 
 */
public class BlockTree extends StatementTree {

	private List<StatementTree> statements;
	private SymbolTable symbolTable;

	/**
	 * constructs block tree
	 * 
	 * @param parent
	 */
	public BlockTree(BlockTree parent) {
		this.log.debug("> BlockTree parent: {}", parent != null);
		if (parent == null) {
			this.symbolTable = new HashSymbolTable(null);
		} else {
			this.symbolTable = new HashSymbolTable(parent.getSymbolTable());
		}
		this.statements = new LinkedList<StatementTree>();
		this.log.debug("< BlockTree");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cz.cvut.fit.crhonjar.mi.run.hawera.tree.Tree#accept(cz.cvut.fit.crhonjar
	 * .mi.run.hawera.tree.TreeVisitor)
	 */
	@Override
	public void accept(TreeVisitor visitor) {
		visitor.visitBlock(this);

	}

	/**
	 * return number of statements in block
	 * 
	 * @return
	 */
	public int countOfStatements() {
		int n = this.statements.size();
		this.log.debug(">< countOfStatements result: {}", n);
		return n;
	}

	/**
	 * @return the statements
	 */
	public List<StatementTree> getStatements() {
		this.log.debug(">< getStatements");
		return this.statements;
	}

	/**
	 * @return the symbolTable
	 */
	public SymbolTable getSymbolTable() {
		this.log.debug(">< getSymbolTable");
		return this.symbolTable;
	}

}
